package com.example.demo.LeetCode.arr;

public class SearchMatrix {
    public static boolean solution(int[][] matrix,int target){
        int row = matrix.length;
        //在列中二分查找,找到第一个不大于目标值的行
        int left = -1,right = row-1;
        while (left < right){
            int mid = (right - left + 1) / 2 + left;
             if (matrix[mid][0] <= target){
                 left = mid;
             }else{
                 right = mid - 1;
             }
        }
        if (left < 0){
            return false;
        }
        int[] arr = matrix[left];
        int aLeft = 0,aRight = arr.length-1;
        while (aLeft <= aRight){
            int mid = (aRight - aLeft) / 2 + aLeft;
            if (arr[mid] == target){
                return true;
            }
            if (arr[mid] < target){
                aLeft = mid+1;
            }else {
                aRight = mid -1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] matrix = {{1}};
        int target = 13;
        System.out.println(solution(matrix,target));
    }




}
